﻿<?php
use common\components\widgets\Datetimepicker;
use doumiaoduo\layer\LayerAsset;
use yii\helpers\Html;
use common\components\helpers\Fun;

LayerAsset::register($this);
Datetimepicker::widget(['flag' => 'timepicker']);
?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height">
    <?= $this->renderFile('@zhtfrontend/views/layouts/toolbar.php'); ?>
    <div id="search-area" class="yx-bgf7f7f7 yx-radius5 zx-mg yx-function2 yx-pr0">
        <?= Html::beginForm(Fun::url(['admission/index']), 'get', ['enctype' => 'multipart/form-data']) ?>
        <?= \common\components\helpers\Search::dropDownList('mechanism_id', null, array_merge([null => '请选择'], $listData), ['label' => '机构', 'promote' => '请选择机构', 'class' => 'search diy_select_txt']) ?>
        <?= \common\components\helpers\Search::textInput('searchDate', \Yii::$app->request->get('searchDate'), ['label' => '日期', 'class' => 'timepicker yx-input-text zx-width150 yx-ml6']); ?>
        <?= \common\components\helpers\Search::dropDownList('searchWay', null, [null => '请选择', 1 => '按月', 2 => '按日'], ['label' => '按月按日', 'promote' => '请选择..', 'class' => 'search diy_select_txt']) ?>
        <?= \common\components\helpers\Search::dropDownList('state', null, [null => '请选择', 2 => '未结算', 1 => '已结算'], ['label' => '状态', 'promote' => '请选择..', 'class' => 'search diy_select_txt']) ?>
        <?= \common\components\helpers\Search::submitButton('搜索', ['id' => 'search-handle', 'class' => "yx-search yx-radius2"]); ?>
        <?php Html::endForm() ?>
    </div>
    <div class="docs-main zx-mg">
        <table id="tablesaw" class="tablesaw table yx-table1 yx-table5 table-striped with-check">
            <thead>
            <tr class="yx-bgd2f6ec">
                <th><?= \Yii::t('zhtfrontend', 'ID'); ?></th>
                <th><?= \Yii::t('zhtfrontend', '商品或课程'); ?></th>
                <th><?= \Yii::t('zhtfrontend', '所属机构'); ?></th>
                <th><?= \Yii::t('zhtfrontend', '学生姓名'); ?></th>
                <th><?= \Yii::t('zhtfrontend', '招生时间'); ?></th>
                <th><?= \Yii::t('zhtfrontend', '结算状态'); ?></th>
            </tr>
            </thead>
            <?php if ($data): ?>
                <?php foreach ($data as $item): ?>
                    <tr data-id="<?= $item['id'] ?>">
                        <td><?= $item['id'] ?></td>
                        <td><?= $item['goods_name'] ?></td>
                        <td><?= $item['mechanic_name'] ?></td>
                        <td><?= $item['student_name'] ?></td>
                        <td><?= $item['created_at'] ?></td>
                        <td><?= $item['status'] ?></td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </table>
        <div style="text-align: right"><?= common\components\widgets\GoPager::widget(['pagination' => $pages]) ?></div>
    </div>
</div>
<?php
$js = <<<JS
    layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });
    $("#dialog-show-iframe").click(function (e) {
        e.stopPropagation();
        var ids = '';
        $('input[name="checkbox"]:checked').each(function () {
             var val = $(this).val();
            (ids == '') ? ids = val : ids += ',' + val;
        });
        if (ids == '') {
           layer.msg("请先选择需要结算的记录！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
            return false;
        }
        else {
            var url = $(this).data('url');
             layer.confirm(layout+'<p>已结算的不再结算？</p>', {
                title: '结算',
                area: ['440px', '270px'],
                skin: 'layui-confirm-customskin',
                shift:1,
                id:'layer-iframe',
                btn: ['确定','取消'],
                yes: function(index, layero){
                   $.post(url, {ids: ids,_csrf:yii.getCsrfToken()}, function (data) {
                        if(data == 1){
                            alert('结算成功');
                            window.location.reload();
                        }
                        if(data == 2){
                            alert('此记录已结算');
                            window.location.reload()
                        }
                        if(data == 3){
                           alert('系统错误请重试');
                        }
                    }, 'json');
                  layer.close(index);
                }
          });
        }
    });
JS;
$this->registerJS($js);
?>



